package com.kancy.xml.entity;

import com.kancy.xml.adapter.DateAdapter;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**使用了XmlType 需要指定所有字段顺序*/
@XmlType(propOrder = {
        "describ","productDate","className","properties"
})
/**
 * 当没有指定@XmlAccessorType注解时，@XmlElement 和@XmlAttribute 只能放在get/set方法上否则会报错；
 * 当有@XmlAccessorType注解时，可以在字段上添加@XmlElement，@XmlAttribute，@XmlJavaTypeAdapter做说明
 */
public class Service {
    // 生成日期
    private Date productDate;

    private String className;

    private String describ;

    private List<Property> properties = new ArrayList<Property>();

    @XmlElement(name="class")
    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }
    @XmlElement(name="describ")
    public String getDescrib() {
        return describ;
    }

    public void setDescrib(String describ) {
        this.describ = describ;
    }

    public Service() {
    }

    public Service(String className, String describ) {
        this.className = className;
        this.describ = describ;
    }

    public List<Property> getProperties() {
        return properties;
    }

    @XmlElementWrapper(name="properties")
    @XmlElement(name="property")
    public void setProperties(List<Property> properties) {
        this.properties = properties;
    }

    public Date getProductDate() {
        return productDate;
    }

    /**加上nillable 说明可以使此节点具有空节点的能力，当节点的值为null时，展示空节点，默认情况是直接删除节点*/
    @XmlElement(name="productDate", nillable = true , required = true)
    @XmlJavaTypeAdapter(value=DateAdapter.class, type=Date.class)
    public void setProductDate(Date productDate) {
        this.productDate = productDate;
    }

    @Override
    public String toString() {
        return "Service{" +
                "productDate=" + productDate +
                ", className='" + className + '\'' +
                ", describ='" + describ + '\'' +
                ", properties=" + properties +
                '}';
    }
}
